import pptx
from pptx import Presentation
from pptx.util import Cm
import os

prs=Presentation('Test.pptx')

def getfiles(path):
    """获取目录下的文件\n
    args:
        path:路径
    return
        files:string[]
    """
    files=[]
    names=[]
    for f in os.listdir(path):
        if not f.endswith('~') or not f.startswith('~') or not f=="":
            files.append(os.path.join(path,f))
            names.append(f)
    return files
    # ,names

def testpptx():
    for slide in prs.slides:
        for shape in slide.shapes:
            print(shape)
            if shape.has_text_frame:
                text_frame=shape.text_frame
                print(text_frame.text)
                for paragraph in text_frame.paragraphs:
                    print(paragraph.text)
        print(slide)
    for shape in slide.placeholders:
        phf=shape.placeholder_format
        print(f"{phf.idx}--{shape.name}--{phf.type}")

def addimage(file):
    """
    添加图片
    """
    black_slide_layout=prs.slide_layouts[0]
    slide=prs.slides.add_slide(black_slide_layout)
    left=top=Cm(0)
    height=Cm(33.87)
    width=Cm(19.05)
    pic=slide.shapes.add_picture(file,left,top,height,width)
    

if __name__=='__main__':
    res=getfiles('./images');
    for f in res:
        addimage(f)
    prs.save('test1.pptx')